package com.guhappy.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.guhappy.action.model.RollingStockBean;
import com.guhappy.util.business.BusinessUtil;
import com.opensymphony.xwork2.ActionSupport;

public class JsonRollingBarBean extends ActionSupport {
	private static final Log log = LogFactory.getLog(JsonRollingBarBean.class);
	private List<RollingStockBean> stock;
	private static final Map<String, String> myMap;
    static
    {
        myMap = new HashMap<String, String>();
        myMap.put("United States", "1");
        myMap.put("Canada", "2");
        myMap.put("North America", "3");
        myMap.put("China", "4");
        myMap.put("Hongkong", "5");
        myMap.put("Taiwan", "6");
        myMap.put("Singapore", "7");
        myMap.put("Austrilia", "8");
        myMap.put("London", "9");
        myMap.put("Korea", "10");
    }
	

	private String area;

	public String execute() throws Exception {
		return SUCCESS;
	}

	public String listStock() {
		log.info("build json lists area : " + area);
		// now we do it manual, later we change to database

	/*	<li><a href="javascript:void(0)">United States</a></li>
		<li><a href="javascript:void(0)">Canada</a></li>
		<li><a href="javascript:void(0)">North America</a></li>
		<li><a href="javascript:void(0)">China</a></li>
		<li><a href="javascript:void(0)">Hongkong</a></li>
		<li><a href="javascript:void(0)">Taiwan</a></li>
		<li><a href="javascript:void(0)">Singapore</a></li>
		<li><a href="javascript:void(0)">Austrilia</a></li>
		<li><a href="javascript:void(0)">London</a></li>
		<li><a href="javascript:void(0)">Korea</a></li>
		*/

		if (area != null && !area.trim().equals("")) {
			stock = BusinessUtil.stockListUtil(myMap.get(area));
		}
		return SUCCESS;
	}

	public String getJSON() {
		return listStock();
	}

	public List<RollingStockBean> getStock() {
		return stock;
	}

	public void setStock(List<RollingStockBean> stock) {
		this.stock = stock;
	}

	public void setArea(String area) {
		this.area = area;
	}

	public String getArea() {
		return area;
	}
}
